#include <iostream>
#include <jsoncpp/json/json.h>
#include <fstream>


struct stu
{
    std::string name;
    int age;
    double weight;
public:
    void debug()
    {
        std::cout << name << std::endl;
        std::cout << age << std::endl;
        std::cout << weight << std::endl;
    }
};

int main()
{
    //不知道文件里面有多少字符
    std::ifstream in("out.txt");
    if(!in.is_open())
    {   
        std::cout << "error";
        return 1;
    }
    //从文件中读取到buffer，字符串
    char buffer[1024];
    in.read(buffer,sizeof(buffer)-1);
    std::cout << buffer;

    //将buffer反序列化

    std::string json_string = buffer;
    Json::Value root;
    Json::Reader reader;
    bool ret = reader.parse(json_string,root);

    struct stu a;
    a.name = root["name"].asString();
    a.age = root["age"].asInt();
    a.weight = root["weight"].asDouble();


    a.debug();

    in.close();
}
 

// int main()
// {

//     //结构化数据
//     struct stu a = {"1",18,70.5};

//     //将结构化数据序列号
//     Json::Value root;
//     root["name"] = a.name;
//     root["age"] = a.age;
//     root["weight"] = a.weight;


//     //Json::FastWriter writer;
//     Json::StyledWriter writer;
//     std::string str1 = writer.write(root);

//     std::cout << str1<<std::endl;

//     //将序列化的数据输出到文件中
//     std::ofstream out("out.txt");
//     if(!out.is_open())
//     {
//         std::cout << str1;
//         return 1;
//     }

//     out << str1;
//     out.close();
//     return 0;
// }
